package ee.ut.test;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang3.time.DateUtils;

import ee.ut.test.adapter.ScheduleTimeListAdapter;
import ee.ut.test.model.ScheduleTimeListItem;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

public class ScheduleTimeListActivity extends Activity{

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.schedule_time_list);
        
        Button callDocButton = (Button) findViewById(R.id.scheduleTimeCallDoc);
        callDocButton.setOnClickListener(new CallDoctorButtonOnClickListener());
        
        String staffName = getIntent().getExtras().getString(ResultListActivity.STAFF_NAME_KEY);
        TextView textView = (TextView) findViewById(R.id.scheduleTimeListStaff);
        textView.setText(staffName);
        
        ListView listView = (ListView) findViewById(R.id.scheduleTimeList);
        listView.setAdapter(new ScheduleTimeListAdapter(this, createTestData()));
    }
    
    protected final class CallDoctorButtonOnClickListener implements OnClickListener {

		@Override
		public void onClick(View v) {
			Intent intent = new Intent(Intent.ACTION_CALL);
			intent.setData(Uri.parse("tel:23434276"));
			startActivity(intent);
		}
    	
    }
    
    private List<ScheduleTimeListItem> createTestData(){
    	List<ScheduleTimeListItem> items = new ArrayList<ScheduleTimeListItem>();
    	ScheduleTimeListItem item = new ScheduleTimeListItem();
    	item.setId(1L);
    	item.setDate(new Date());
    	items.add(item);

    	ScheduleTimeListItem item2 = new ScheduleTimeListItem();
    	item2.setId(2L);
    	item2.setDate(new Date());
    	items.add(item2);
    	
    	ScheduleTimeListItem item3 = new ScheduleTimeListItem();
    	item3.setId(3L);
    	item3.setDate(new Date());
    	items.add(item3);
    	
    	ScheduleTimeListItem item4 = new ScheduleTimeListItem();
    	item4.setId(4L);
    	item4.setDate(DateUtils.addDays(new Date(), 1));
    	items.add(item4);
    	
    	ScheduleTimeListItem item5 = new ScheduleTimeListItem();
    	item5.setId(5L);
    	item5.setDate(DateUtils.addDays(new Date(), 1));
    	items.add(item5);
    	
    	ScheduleTimeListItem item6 = new ScheduleTimeListItem();
    	item6.setId(6L);
    	item6.setDate(DateUtils.addDays(new Date(), 1));
    	items.add(item6);
    	
    	ScheduleTimeListItem item7 = new ScheduleTimeListItem();
    	item7.setId(7L);
    	item7.setDate(DateUtils.addDays(new Date(), 1));
    	items.add(item7);
    	
    	ScheduleTimeListItem item8 = new ScheduleTimeListItem();
    	item8.setId(8L);
    	item8.setDate(DateUtils.addDays(new Date(), 2));
    	items.add(item8);
    	
    	return items;
    }
}
